
<template>
  <div class="main-container">
    <div class="filtrate-bar">
      <div class="title-box">
        <div class="icon-box">
          <span class="iconfont icon-yuangong" />
        </div>
        <span class="text" style="margin-right: 10px">员工类型分布</span>
        <a-radio-group v-if="isAllData" v-model="parentId" button-style="solid" @change="getDepartments">
          <a-radio-button value="1"> 全部 </a-radio-button>
          <a-radio-button value="73"> 总部 </a-radio-button>
        </a-radio-group>
        <span v-if="isAllData" class="search-label" style="margin-left: 10px">部门：</span>
        <a-select v-if="isAllData" v-model="departmentIds" mode="multiple" style="width: 300px" placeholder="请选择" @change="handleDepartmentChange">
          <a-select-option v-for="item in departmentIdList" :key="item.departmentId">
            {{ item.name }}
          </a-select-option>
        </a-select>
        <span class="search-label" style="margin-left: 10px">是否管培生：</span>
        <j-dict-select-tag
          style="width: 200px"
          type="list"
          v-model="params.isGuanPeiSheng"
          :trigger-change="true"
          @change="isguanpeishengChange"
          dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId = BOOL_DEFINE"
          placeholder="请选择是否管培生"
        />
        <a-button type="primary" @click="getDataList" style="margin-left: 10px" icon="search">查询</a-button>
      </div>
    </div>

    <div class="content">
      <div class="table-content">
        <div class="handle-bar">
          <!--
          <a-button class="export-btn" type="primary" icon="download" @click="handleExportXls">导出</a-button>
          -->
        </div>
        <a-table :columns="columns" :data-source="dataList" :pagination="false" bordered :scroll="{ y: 550 }">
          <template slot="departmentName" slot-scope="text, record">
            <a-tooltip placement="top">
              <template slot="title">
                <span>{{ record.departmentName }}</span>
              </template>
              <span class="ellipsis" style="text-align: center; width: 100%"
                ><a @click="() => showReason(record)">{{ record.departmentName }}</a></span
              >
            </a-tooltip>
          </template>
        </a-table>
      </div>
    </div>

    <a-card :bordered="false" title="员工类型占比">
      <div id="echart5" style="height: 400px; width: 90%"></div>
    </a-card>

    <employee-type ref="employeeType"></employee-type>
  </div>
</template>

<script>
import JDate from '@/components/jeecg/JDate.vue'
import JCategorySelect from '@/components/jeecg/JCategorySelect'
import { postAction, getAction, downFile } from '@/api/manage'
import EmployeeType from './components/employeeType'
export default {
  name: 'statistics',
  components: {
    JDate,
    EmployeeType,
    JCategorySelect,
  },

  data() {
    return {
      isAllData: this.$store.getters.buData == 'allhrdata' ? true : false,
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 100,
          align: 'center',
          customRender: function (t, r, index) {
            if (r.rank == '汇总') {
              return '汇总'
            } else {
              return parseInt(index) + 1
            }
          },
        },
        {
          title: 'BU',
          align: 'center',
          width: 300,
          dataIndex: 'departmentName',
          filters: [],
          onFilter: (value, record) => record.departmentName.indexOf(value) === 0,
          scopedSlots: { customRender: 'departmentName' },
        },
        {
          title: '总部正式员工',
          align: 'center',
          width: 300,
          dataIndex: 'c1Num',
        },
        {
          title: 'BU正式员工',
          align: 'center',
          width: 300,
          dataIndex: 'c2Num',
        },
        {
          title: '实习生',
          align: 'center',
          dataIndex: 'c8Num',
        },
        {
          title: '派遣工',
          align: 'center',
          dataIndex: 'c9Num',
        },
        {
          title: '临时工',
          align: 'center',
          dataIndex: 'c10Num',
        },
        {
          title: '正式工',
          align: 'center',
          dataIndex: 'c11Num',
        },
      ],
      dataList: [],
      departmentIds: [],
      departmentIdList: [],
      parentId: '1',
      params: {
        ids: '',
        isGuanPeiSheng: '',
      },
      chartOptions5: {
        tooltip: {
          trigger: 'item',
        },
        legend: {
          top: '0',
          left: 'center',
        },
        series: [
          {
            name: '员工类型占比',
            type: 'pie',
            radius: ['40%', '70%'],
            avoidLabelOverlap: false,
            labelLine: {
              show: true,
            },
            data: [],
          },
        ],
      },
      url: {
        getEmployeeTypeReport: '/online/api/getEmployeeTypeReport',
        listHrDepartmentByAllHrData: '/online/api/listHrDepartmentByAllHrData',
        exportXlsUrl: '/online/api/export/exportXlsGraphReport',
      },
    }
  },
  computed: {},
  //watch: {},
  mounted() {
    this.getDepartments()
  },
  methods: {
    getDepartments() {
      this.departmentIds = []
      getAction(this.url.listHrDepartmentByAllHrData, {parentId: this.parentId}).then((res) => {
        if (res.success) {
          this.departmentIdList = res.result
        }
      })
      this.getDataList()
    },
    handleDepartmentChange(e) {
      this.departmentIds = e
    },
    isguanpeishengChange(e) {
      this.params.isGuanPeiSheng = e
    },
    drawBar() {
      let chartDom5 = document.getElementById('echart5')
      let myChart5 = this.echarts.init(chartDom5)
      myChart5.setOption(this.chartOptions5)
    },
    getDataList() {
      this.params.parentId = this.parentId
      this.params.ids = this.departmentIds.join(';')
      if(!this.isAllData){
        this.params.userLoginDepartmentId = this.$store.getters.departmentId
      }
      getAction(this.url.getEmployeeTypeReport, this.params).then((res) => {
        if (res.success) {
          this.columns[1].filters = []
          res.result.records.forEach((e) => {
            this.columns[1].filters.push({
              text: e.departmentName,
              value: e.departmentName,
            })
            if (e.departmentName == '汇总') {
              this.chartOptions5.series[0].data = [
                { name: '总部正式员工', value: e.c1Num },
                { name: 'BU正式员工', value: e.c2Num },
                { name: '实习生', value: e.c8Num },
                { name: '派遣工', value: e.c9Num },
                { name: '临时工', value: e.c10Num },
                { name: '正式工', value: e.c11Num },
              ]
            }
          })
          this.drawBar()
          this.dataList = res.result.records
        }
      })
    },

    /**
     * 导出点击
     */
    exportClick() {
      this.requestExportInfo(biCustomerTotalListExportAPI, this.listPostParams)
    },
    showReason(data) {
      this.$refs.employeeType.show(data)
    },
  },
}
</script>


<style lang="less" scoped>
.main-container {
  border: 1px solid #e6e6e6;
  border-radius: 2px;
  background-color: white;
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  position: relative;
}

.filtrate-bar {
  background-color: white;
  padding: 15px 20px 5px 20px;
  margin-right: 15px;
  line-height: 34px;
  .icon-box {
    width: 34px;
    height: 34px;
    text-align: center;
    line-height: 34px;
    color: #2362fb;
    background-color: #dfe8ff;
    border-radius: 50%;
    margin-right: 10px;
    float: left;
  }
  .text {
    font-size: 17px;
    font-weight: 700;
  }
}

/deep/ .ant-table-body {
  min-height: 450px;
}

.content {
  height: calc(100% - 54px);
  overflow-y: auto;
  padding: 10px 0;
}

.content-title {
  padding: 10px 20px 5px;
  font-size: 16px;
  color: #333;
}

.axis-content {
  padding: 20px 10% 40px;
  position: relative;
  .axismain,
  #axismain {
    margin: 0 auto;
    width: 95%;
    height: 400px;
  }
}

.table-content {
  padding: 0 60px 20px 60px;
}

.export-button {
  float: right;
  margin-right: 22px;
}

// 导出操作bug
.handle-bar {
  margin-bottom: 8px;
  text-align: right;
}

.search-box {
  padding-right: 15px;
}

.radio-box {
  padding: 0 20px;
  margin-bottom: 15px;
  /deep/ .el-radio__label {
    color: #99a9bf !important;
  }
}

.static {
  padding: 0 20px;
  margin-bottom: 10px;
  .text {
    font-size: 13px;
    color: #99a9bf;
    display: inline-block;
  }
  .text:not(:last-child) {
    margin-right: 15px;
  }
}
</style>

